﻿using Geek.Server.Config.Luban;

namespace Geek.Server.Config
{
    /// <summary>
    /// 配置表服务门面
    /// </summary>
    public static class ConfigurationService
    {
        private static readonly NLog.Logger LOGGER = LogManager.GetCurrentClassLogger();
        public static DateTime ReloadTime { get; private set; }
        private static IConfigurationService Instance { get; set; }

        public static (bool, string) ReloadAll()
        {
            try
            {
                var service = new LubanConfigurationService();
                service.Load();
                Instance = service;
                ReloadTime = DateTime.Now;
                return (true, "");
            }
            catch (Exception e)
            {
                LOGGER.Error(e.Message);
                return (false, e.Message);
            }
        }

        /// <summary>
        /// 获取指定配置表实例
        /// </summary>
        public static T Get<T>() where T : class, IConfiguration
        {
            return Instance.Get<T>();
        }
    }
}